//
//  String+TextWidth.swift
//  ShowDance
//
//  Created by 苏泊尔漫也要按时吃饭 on 2022/12/19.
//

import Foundation
extension String {
    ///计算字体宽度 字体大小
    ///
    public func textWidth(font: UIFont) -> CGFloat {
        let str         = self as NSString
        let size        = CGSize(width: 20000, height: 100)
        let attributes  = [NSAttributedString.Key.font:  font]
        let labelSize   = str.boundingRect(with: size, options: .usesLineFragmentOrigin, attributes: attributes, context: nil).size
        return labelSize.width
    }
}
